package relation;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class Relation {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration conf = new Configuration();
        Job wordcountJob = Job.getInstance(conf);

        //指定job所在的jar包
        wordcountJob.setJarByClass(Relation.class);

        //设置job的逻辑mapper类
        wordcountJob.setMapperClass(RelationMapper.class);
        //设置job的逻辑reducer类
        wordcountJob.setReducerClass(RelationReducer.class);

        //设置map阶段的输出K-V数据类型
        wordcountJob.setMapOutputKeyClass(Text.class);
        wordcountJob.setMapOutputValueClass(Text.class);

        //设置最终输出的K-V数据类型
        wordcountJob.setOutputKeyClass(Text.class);
        wordcountJob.setOutputValueClass(Text.class);

        //设置要处理的文本数据所存放的路径
        FileInputFormat.setInputPaths(wordcountJob, new Path("hdfs://127.0.0.1:9000/relation/input"));
        FileOutputFormat.setOutputPath(wordcountJob, new Path("hdfs://127.0.0.1:9000/relation/output"));

        //提交job给集群
        wordcountJob.waitForCompletion(true);
    }
}
